package com.file.word;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;

/**
 * @author: cxt
 * @time: 2022/3/1
 */
@RequestMapping("/word/test")
@RestController
public class WordTest {
    @GetMapping("/byModel")
    public void export(HttpServletRequest request, HttpServletResponse response) {
        HashMap<String, Object> map = generateData();
        try {
            ExportWordUtils.exportWord("src/main/resources/json/111.docx", "D://", "测试的生成的文档.docx", map, request, response);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    private static HashMap<String, Object> generateData() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("name", "张XX");
        map.put("sex", "男");
        map.put("age", "22");
        map.put("cardId", "222265654541");
        map.put("date", "2022-3-1");
        return map;
    }

}